package org.example;

import com.alibaba.fastjson2.JSON;
import org.example.dataStorage.Json.JsonStorageConfig;
import org.example.dataStorage.Json.JsonStorageService;
import org.junit.Test;

public class DataStorageMainTest {
    static class txt_user {
        public String name;
        public int age;

        @Override
        public String toString() {
            return "txt_user{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }

    /**
     * 测试添加数据 并保存到本地
     */
    @Test
    public void testGetDataStorage() {
        JsonStorageConfig jsonStorageConfig = new JsonStorageConfig();
        jsonStorageConfig.setFILE_NAME("UserApp.config");
        JsonStorageService jsonStorageService = new JsonStorageService(jsonStorageConfig);
        String json = jsonStorageService.getJSON();
        System.out.println(json);
        txt_user parse = JSON.parseObject(json, txt_user.class);
        System.out.println(parse);

    }

    /**
     * 测试 读取本地数据
     */
    @Test
    public void testSetMouseProcessingStorage() {
        JsonStorageConfig jsonStorageConfig = new JsonStorageConfig();
        jsonStorageConfig.setFILE_NAME("UserApp.config");
        JsonStorageService jsonStorageService = new JsonStorageService(jsonStorageConfig);
        txt_user txtUser = new txt_user();
        txtUser.age = 12;
        txtUser.name = "cs";
        jsonStorageService.setJSON(txtUser);

    }
}
